﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace SpaceKinect
{
    class Target:GameObject
    {
        Model model;
        protected float radius;

        Random random = new Random();

        //variables to hold the random change in each axis
        float xChange = 0;
        float yChange = 0;
        float zChange = 0;

        float lastChange = -1;

        Random rnd = new Random();

        public Target (Model m, Vector3 p, float r)
        {
            model = m;
            position = p;
            radius = r;
            bound = new BoundingSphere(position, radius);
        }
        
        public float Radius
        {
            get { return radius; }
            set { radius = value; }
        }

        public void Update(Player player, GameTime gameTime, int mapHeight, int mapWidth, float speed)
        {

            //briefly experimented with moving asteroids, but ran out of time

            //Vector3 addVector;

            ////generate random axis directions every second
            //if ((gameTime.TotalGameTime.Seconds - lastChange) >= 1)
            //{
            //    xChange = ((float)rnd.NextDouble()/5);
            //    yChange = ((float)rnd.NextDouble()/5);
            //    zChange = ((float)rnd.NextDouble()/5);
            //    lastChange = gameTime.TotalGameTime.Seconds;
            //}

            ////keeps the UFO inside the tunnel and a certain distance range in front of player
            ////if (position.X - player.Position.X < 35)
            ////    xChange = Math.Abs(xChange);
            ////if (position.X - player.Position.X > 65)
            ////    xChange = -Math.Abs(xChange);

            //if (position.Y < 1)
            //    yChange = Math.Abs(yChange);
            //if (position.Y > mapHeight - 1)
            //    yChange = -Math.Abs(yChange);
            //if (position.Z < -mapWidth + 1)
            //    zChange = Math.Abs(zChange);
            //if (position.Z > -1)
            //    zChange = -Math.Abs(zChange);

            //addVector = Vector3.Transform(new Vector3(0, yChange, zChange), rotation);
            //position += addVector;

            //Create boundingsphere around the UFO
            bound = new BoundingSphere(position, radius);
        }

        public CollisionType CheckTargetSetUpCollision(BoundingBox mapBox, List<Target> targetList)
        {
            //check that a generated target doesn't collide with the tunnel sides
            if (mapBox.Contains(bound) != ContainmentType.Contains)
                return CollisionType.Boundary;

            //check that a generated target doesn't collide with a previously generated target
            for (int i = 0; i < targetList.Count; i++)
            {
                if (targetList[i].Bound.Contains(bound) != ContainmentType.Disjoint)
                    return CollisionType.Target;
            }
            return CollisionType.None;
        }

    }
}
